﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Mani.Common.Security;
using System.Web.Security;

namespace RastinArgham.CRM.Web
{
    public partial class online_users : System.Web.UI.Page
    {
        public ISecurityManager securityManager { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (securityManager == null)
            {
                securityManager = new SecurityManager();
                securityManager.authProvider = new WebAuthorizationProvider();
            }

            if (!securityManager.IsActionPermitted("online_users"))
                Response.Redirect("~/access_denied.aspx");

            if (!Page.IsPostBack)
                LoadUsers();
        }

        private void LoadUsers()
        {
            List<aspnet_Users> users = securityManager.GetOnlineUsers(Membership.ApplicationName);
            lblCount.Text = users.Count.ToString();
            gvUsers.DataSource = users;
            gvUsers.DataBind();
        }

        protected void gvUsers_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvUsers.PageIndex = e.NewPageIndex;
            LoadUsers();
        }
    }
}